home *** CD-ROM | disk | FTP | other *** search
- package javax.crypto;
-
- import java.nio.ByteBuffer;
- import java.security.InvalidAlgorithmParameterException;
- import java.security.InvalidKeyException;
- import java.security.Key;
- import java.security.NoSuchAlgorithmException;
- import java.security.NoSuchProviderException;
- import java.security.Provider;
- import java.security.ProviderException;
- import java.security.spec.AlgorithmParameterSpec;
- import java.util.Iterator;
- import java.util.List;
- import sun.security.jca.GetInstance;
- import sun.security.util.Debug;
-
- public class Mac implements Cloneable {
- // $FF: renamed from: a sun.security.util.Debug
- private static final Debug field_0 = Debug.getInstance("jca", "Mac");
- // $FF: renamed from: b java.security.Provider
- private Provider field_1;
- // $FF: renamed from: c javax.crypto.MacSpi
- private MacSpi field_2;
- // $FF: renamed from: d java.lang.String
- private final String field_3;
- // $FF: renamed from: e boolean
- private boolean field_4 = false;
- // $FF: renamed from: f java.security.Provider.Service
- private Provider.Service field_5;
- // $FF: renamed from: g java.util.Iterator
- private Iterator field_6;
- // $FF: renamed from: h java.lang.Object
- private final Object field_7;
- // $FF: renamed from: i int
- private static int field_8 = 10;
-
- protected Mac(MacSpi var1, Provider var2, String var3) {
- this.field_2 = var1;
- this.field_1 = var2;
- this.field_3 = var3;
- this.field_6 = null;
- this.field_7 = null;
- }
-
- private Mac(Provider.Service var1, Iterator var2, String var3) {
- this.field_5 = var1;
- this.field_6 = var2;
- this.field_3 = var3;
- this.field_7 = new Object();
- }
-
- public final String getAlgorithm() {
- return this.field_3;
- }
-
- public static final Mac getInstance(String var0) throws NoSuchAlgorithmException {
- List var1 = GetInstance.getServices("Mac", var0);
- Iterator var2 = var1.iterator();
-
- while(var2.hasNext()) {
- Provider.Service var3 = (Provider.Service)var2.next();
- if (SunJCE_b.b(var3.getProvider())) {
- return new Mac(var3, var2, var0);
- }
- }
-
- throw new NoSuchAlgorithmException("Algorithm " + var0 + " not available");
- }
-
- public static final Mac getInstance(String var0, String var1) throws NoSuchAlgorithmException, NoSuchProviderException {
- GetInstance.Instance var2 = SunJCE_b.a("Mac", MacSpi.class, var0, var1);
- return new Mac((MacSpi)var2.impl, var2.provider, var0);
- }
-
- public static final Mac getInstance(String var0, Provider var1) throws NoSuchAlgorithmException {
- GetInstance.Instance var2 = SunJCE_b.a("Mac", MacSpi.class, var0, var1);
- return new Mac((MacSpi)var2.impl, var2.provider, var0);
- }
-
- // $FF: renamed from: a () void
- void method_0() {
- if (this.field_2 == null && this.field_6 != null) {
- synchronized(this.field_7) {
- if (this.field_2 == null) {
- if (field_0 != null) {
- int var2 = --field_8;
- if (var2 >= 0) {
- field_0.println("Mac.init() not first method called, disabling delayed provider selection");
- if (var2 == 0) {
- field_0.println("Further warnings of this type will be suppressed");
- }
-
- (new Exception("Call trace")).printStackTrace();
- }
- }
-
- NoSuchAlgorithmException var8 = null;
-
- while(this.field_5 != null || this.field_6.hasNext()) {
- Provider.Service var3;
- if (this.field_5 != null) {
- var3 = this.field_5;
- this.field_5 = null;
- } else {
- var3 = (Provider.Service)this.field_6.next();
- }
-
- if (SunJCE_b.b(var3.getProvider())) {
- try {
- Object var4 = var3.newInstance((Object)null);
- if (var4 instanceof MacSpi) {
- this.field_2 = (MacSpi)var4;
- this.field_1 = var3.getProvider();
- this.field_5 = null;
- this.field_6 = null;
- return;
- }
- } catch (NoSuchAlgorithmException var6) {
- var8 = var6;
- }
- }
- }
-
- ProviderException var9 = new ProviderException("Could not construct MacSpi instance");
- if (var8 != null) {
- var9.initCause(var8);
- }
-
- throw var9;
- }
- }
- }
- }
-
- // $FF: renamed from: a (java.security.Key, java.security.spec.AlgorithmParameterSpec) void
- private void method_1(Key var1, AlgorithmParameterSpec var2) throws InvalidKeyException, InvalidAlgorithmParameterException {
- synchronized(this.field_7) {
- if (this.field_2 != null) {
- this.field_2.engineInit(var1, var2);
- } else {
- Exception var4 = null;
-
- while(this.field_5 != null || this.field_6.hasNext()) {
- Provider.Service var5;
- if (this.field_5 != null) {
- var5 = this.field_5;
- this.field_5 = null;
- } else {
- var5 = (Provider.Service)this.field_6.next();
- }
-
- if (var5.supportsParameter(var1) && SunJCE_b.b(var5.getProvider())) {
- try {
- MacSpi var6 = (MacSpi)var5.newInstance((Object)null);
- var6.engineInit(var1, var2);
- this.field_1 = var5.getProvider();
- this.field_2 = var6;
- this.field_5 = null;
- this.field_6 = null;
- return;
- } catch (Exception var8) {
- if (var4 == null) {
- var4 = var8;
- }
- }
- }
- }
-
- if (var4 instanceof InvalidKeyException) {
- throw (InvalidKeyException)var4;
- } else if (var4 instanceof InvalidAlgorithmParameterException) {
- throw (InvalidAlgorithmParameterException)var4;
- } else if (var4 instanceof RuntimeException) {
- throw (RuntimeException)var4;
- } else {
- String var10 = var1 != null ? var1.getClass().getName() : "(null)";
- throw new InvalidKeyException("No installed provider supports this key: " + var10, var4);
- }
- }
- }
- }
-
- public final Provider getProvider() {
- this.method_0();
- return this.field_1;
- }
-
- public final int getMacLength() {
- this.method_0();
- return this.field_2.engineGetMacLength();
- }
-
- public final void init(Key var1) throws InvalidKeyException {
- try {
- if (this.field_2 != null) {
- this.field_2.engineInit(var1, (AlgorithmParameterSpec)null);
- } else {
- this.method_1(var1, (AlgorithmParameterSpec)null);
- }
- } catch (InvalidAlgorithmParameterException var3) {
- throw new InvalidKeyException("init() failed", var3);
- }
-
- this.field_4 = true;
- }
-
- public final void init(Key var1, AlgorithmParameterSpec var2) throws InvalidKeyException, InvalidAlgorithmParameterException {
- if (this.field_2 != null) {
- this.field_2.engineInit(var1, var2);
- } else {
- this.method_1(var1, var2);
- }
-
- this.field_4 = true;
- }
-
- public final void update(byte var1) throws IllegalStateException {
- this.method_0();
- if (!this.field_4) {
- throw new IllegalStateException("MAC not initialized");
- } else {
- this.field_2.engineUpdate(var1);
- }
- }
-
- public final void update(byte[] var1) throws IllegalStateException {
- this.method_0();
- if (!this.field_4) {
- throw new IllegalStateException("MAC not initialized");
- } else {
- if (var1 != null) {
- this.field_2.engineUpdate(var1, 0, var1.length);
- }
-
- }
- }
-
- public final void update(byte[] var1, int var2, int var3) throws IllegalStateException {
- this.method_0();
- if (!this.field_4) {
- throw new IllegalStateException("MAC not initialized");
- } else {
- if (var1 != null) {
- if (var2 < 0 || var3 > var1.length - var2 || var3 < 0) {
- throw new IllegalArgumentException("Bad arguments");
- }
-
- this.field_2.engineUpdate(var1, var2, var3);
- }
-
- }
- }
-
- public final void update(ByteBuffer var1) {
- this.method_0();
- if (!this.field_4) {
- throw new IllegalStateException("MAC not initialized");
- } else if (var1 == null) {
- throw new IllegalArgumentException("Buffer must not be null");
- } else {
- this.field_2.engineUpdate(var1);
- }
- }
-
- public final byte[] doFinal() throws IllegalStateException {
- this.method_0();
- if (!this.field_4) {
- throw new IllegalStateException("MAC not initialized");
- } else {
- byte[] var1 = this.field_2.engineDoFinal();
- this.field_2.engineReset();
- return var1;
- }
- }
-
- public final void doFinal(byte[] var1, int var2) throws ShortBufferException, IllegalStateException {
- this.method_0();
- if (!this.field_4) {
- throw new IllegalStateException("MAC not initialized");
- } else {
- int var3 = this.getMacLength();
- if (var1 != null && var1.length - var2 >= var3) {
- byte[] var4 = this.doFinal();
- System.arraycopy(var4, 0, var1, var2, var3);
- } else {
- throw new ShortBufferException("Cannot store MAC in output buffer");
- }
- }
- }
-
- public final byte[] doFinal(byte[] var1) throws IllegalStateException {
- this.method_0();
- if (!this.field_4) {
- throw new IllegalStateException("MAC not initialized");
- } else {
- this.update(var1);
- return this.doFinal();
- }
- }
-
- public final void reset() {
- this.method_0();
- this.field_2.engineReset();
- }
-
- public final Object clone() throws CloneNotSupportedException {
- this.method_0();
- Mac var1 = (Mac)super.clone();
- var1.field_2 = (MacSpi)this.field_2.clone();
- return var1;
- }
- }
-